#!/bin/sh

PREPARE=$1
LANG="$2"
CVERSION=4.6rc3
VERSION="$(cat data/eversion)"
CFG="tinycore.cfg"
ISODIR="/mnt/sda2/eCore"
TESTDIR="/mnt/sda1/boot/iso"
THISDIR=`pwd`
CDLOCATION=/mnt/sda2/distro/TinyCore-$CVERSION.iso
EZTMPDIR=/mnt/sda2/tmp/ezremaster/

[ "$LANG" ] && LANG=_$LANG
if [ ! -f /usr/local/tce.installed/mkisofs-tools ]; then
   if [ ! -e /etc/sysconfig/tcedir/optional/mkisofs-tools.tcz ]; then
      tce-load -w mkisofs-tools
   fi
      tce-load -is mkisofs-tools
fi
if [ ! -f /usr/local/tce.installed/advcomp ]; then
   if [ ! -e /etc/sysconfig/tcedir/optional/advcomp.tcz ]; then
      tce-load -w advcomp
   fi
      tce-load -is advcomp
fi
./remaster.sh $CFG checkimage
./remaster.sh $CFG extractimage
#./remaster.sh $CFG bootcode
sleep 4
#	echo -n "Next apps.Press Enter key."
#	read gagme
./remaster.sh $CFG apps
sudo rm onboot/*
sudo mv ezremaster/image/cde ezremaster/image/tce
if [ "$LANG" = "_it" ];then 
   sudo cp data/iso/boot_it.msg 	ezremaster/image/boot/isolinux/boot.msg
else
   sudo cp data/iso/isolinux.cfg 	ezremaster/image/boot/isolinux
   sudo cp data/iso/boot.msg 		ezremaster/image/boot/isolinux
   sudo cp data/iso/boot.msg 		ezremaster/image/boot/isolinux/f1
fi
sudo cp data/iso/menu.c32		ezremaster/image/boot/isolinux/
sudo cp data/iso/isolinux.bin		ezremaster/image/boot/isolinux/
sudo cp data/scripts/tc-config   	ezremaster/extract/etc/init.d/
sudo cp data/scripts/e-tc-functions   	ezremaster/extract/etc/init.d/
sudo cp data/scripts/tce-setup   	ezremaster/extract/usr/bin/
sudo cp data/scripts/fromISOfile 	ezremaster/extract/usr/bin/
sudo cp data/scripts/filetool.sh 	ezremaster/extract/usr/bin/
sudo cp data/scripts/bootlocal.sh	ezremaster/extract/opt/
echo -n "Next step package. Press Enter key."
read gagme
./remaster.sh $CFG package
cp ezremaster/ezremaster.iso "$TESTDIR"
sudo mv ezremaster/ezremaster.iso "$ISODIR/TinyCoretst-$VERSION.iso"
#echo -n "Next step CD version. Press Enter key."
#read gagme
#sudo mv ezremaster/image/tce ezremaster/image/cde
#sudo sed -i "s/quiet/quiet cde/" ezremaster/image/boot/isolinux/isolinux.cfg 	
#sudo mkisofs -l -J -R -V eCore -no-emul-boot -boot-load-size 4 \
#	-boot-info-table -b boot/isolinux/isolinux.bin \
#	-c boot/isolinux/boot.cat -o $EZTMPDIR/ezremaster.iso . || exit 24
#sudo mv ezremaster/ezremaster.iso "$ISODIR/eCoreCD-$VERSION.iso"
